package com.example.sunmiv1.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.CreditOrderListInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CreditOrderAdapter extends BaseAdapter {


    private List<CreditOrderListInfo.DataBean.ListBean> list;
    private ViewHolder viewHolder;
    private int screenType = 2;

    public CreditOrderAdapter(List<CreditOrderListInfo.DataBean.ListBean> list) {
        this.list = list;
    }

    public void setScreenType(int screenType) {
        this.screenType = screenType;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_credit_order, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CreditOrderListInfo.DataBean.ListBean bean = list.get(position);
        if (screenType == 2) {//賒賬
            viewHolder.itemCreditOrderMoneyTip.setText(R.string.creditMoney);
            viewHolder.itemCreditOrderTimeTip.setText(R.string.creditTime);
        } else {
            viewHolder.itemCreditOrderMoneyTip.setText(R.string.repayMoney);
            viewHolder.itemCreditOrderTimeTip.setText(R.string.repayTime);
        }
        viewHolder.itemCreditOrderStoreName.setText(bean.getStore_name());
        viewHolder.itemCreditOrderNickName.setText(bean.getNickname());
        viewHolder.itemCreditOrderName.setText(bean.getVip_name());
        viewHolder.itemCreditOrderPhone.setText(bean.getMobile_phone());
        viewHolder.itemCreditOrderMoney.setText(bean.getTotal_money());
        viewHolder.itemCreditOrderTime.setText(bean.getEdit_time());
        viewHolder.itemCreditOrderOrderNo.setText(bean.getOrder_no());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.itemCreditOrder_storeName)
        TextView itemCreditOrderStoreName;
        @BindView(R.id.itemCreditOrder_nickName)
        TextView itemCreditOrderNickName;
        @BindView(R.id.itemCreditOrder_name)
        TextView itemCreditOrderName;
        @BindView(R.id.itemCreditOrder_phone)
        TextView itemCreditOrderPhone;
        @BindView(R.id.itemCreditOrder_moneyTip)
        TextView itemCreditOrderMoneyTip;
        @BindView(R.id.itemCreditOrder_money)
        TextView itemCreditOrderMoney;
        @BindView(R.id.itemCreditOrder_timeTip)
        TextView itemCreditOrderTimeTip;
        @BindView(R.id.itemCreditOrder_time)
        TextView itemCreditOrderTime;
        @BindView(R.id.itemCreditOrder_orderNo)
        TextView itemCreditOrderOrderNo;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
